import 'dart:ffi';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'stripe_terminal_tap_to_pay_platform_interface.dart';

/// An implementation of [StripeTerminalTapToPayPlatform] that uses method channels.
class MethodChannelStripeTerminalTapToPay extends StripeTerminalTapToPayPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('stripe_terminal_tap_to_pay');

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }
  @override
  Future<void> init(String localId,String result) async{
    await methodChannel.invokeMethod<bool>('init',{
      "localId":localId,
      "result":result,
    });
  }
  @override
  Future<Map> pay(String clientSecret) async{
    Map map = await methodChannel.invokeMethod('pay',{
      "clientSecret":clientSecret,
    });
    return map;
  }

  @override
  Future<bool> permissionAllowed() async{
    return await methodChannel.invokeMethod('permissionAllowed');
  }

  ///取消等待刷卡状态
  @override
  Future<bool> cancelRetrievePaymentIntent() async {
    bool cancel = await methodChannel.invokeMethod("cancelRetrievePaymentIntent");
    return cancel;
  }

  ///取消支付
  @override
  Future<void> cancelProcessPayment() async {
    await methodChannel.invokeMethod("cancelProcessPayment");
  }

}
